home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / src / make-3.69 / default.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-27  |  10.4 KB  |  396 lines

  1. /* Data base of default implicit rules for GNU Make.
  2. Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3. This file is part of GNU Make.
  4.  
  5. GNU Make is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. GNU Make is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with GNU Make; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "make.h"
  20. #include "rule.h"
  21. #include "dep.h"
  22. #include "file.h"
  23. #include "commands.h"
  24. #include "variable.h"
  25.  
  26. /* Define GCC_IS_NATIVE if gcc is the native development environment
  27.    on your system (gcc/bison/flex vs cc/yacc/lex) */
  28.  
  29. #ifdef __MSDOS__
  30. #define GCC_IS_NATIVE
  31. #endif
  32.  
  33. /* This is the default list of suffixes for suffix rules.
  34.    `.s' must come last, so that a `.o' file will be made from
  35.    a `.c' or `.p' or ... file rather than from a .s file.  */
  36.  
  37. static char default_suffixes[]
  38.   = ".out .a .ln .o .c .cc .C .p .f .F .r .y .l .s .S \
  39. .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \
  40. .w .ch .web .sh .elc .el";
  41.  
  42. static struct pspec default_pattern_rules[] =
  43.   {
  44.     { "(%)", "%",
  45.     "$(AR) $(ARFLAGS) $@ $<" },
  46.  
  47.     /* The X.out rules are only in BSD's default set because
  48.        BSD Make has no null-suffix rules, so `foo.out' and
  49.        `foo' are the same thing.  */
  50.     { "%.out", "%",
  51.     "@rm -f $@ \n cp $< $@" },
  52.  
  53.     /* Syntax is "ctangle foo.w foo.ch foo.c".  */
  54.     { "%.c", "%.w %.ch",
  55.     "$(CTANGLE) $^ $@" },
  56.     { "%.tex", "%.w %.ch",
  57.     "$(CWEAVE) $^ $@" },
  58.  
  59.     { 0, 0, 0 }
  60.   };
  61.  
  62. static struct pspec default_terminal_rules[] =
  63.   {
  64.     /* RCS.  */
  65.     { "%", "%,v",
  66.     "+$(CHECKOUT,v)" },
  67.     { "%", "RCS/%,v",
  68.     "+$(CHECKOUT,v)" },
  69.  
  70.     /* SCCS.  */
  71.     { "%", "s.%",
  72.     "$(GET) $(GFLAGS) $< -G $@" },
  73.     { "%", "SCCS/s.%",
  74.     "$(GET) $(GFLAGS) $< -G $@" },
  75.  
  76.     { 0, 0, 0 }
  77.   };
  78.  
  79. static char *default_suffix_rules[] =
  80.   {
  81.     ".o",
  82.     "$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  83.     ".s",
  84.     "$(LINK.s) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  85.     ".S",
  86.     "$(LINK.S) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  87.     ".c",
  88.     "$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  89.     ".cc",
  90.     "$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  91.     ".C",
  92.     "$(LINK.C) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  93.     ".f",
  94.     "$(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  95.     ".p",
  96.     "$(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  97.     ".F",
  98.     "$(LINK.F) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  99.     ".r",
  100.     "$(LINK.r) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  101.     ".mod",
  102.     "$(COMPILE.mod) -o $@ -e $@ $^",
  103.  
  104.     ".def.sym", 
  105.     "$(COMPILE.def) -o $@ $<",
  106.  
  107.     ".sh",
  108.     "cat $< >$@ \n chmod a+x $@",
  109.  
  110.     ".s.o",
  111. #if !defined(M_XENIX) || defined(__GNUC__)
  112.     "$(COMPILE.s) -o $@ $<",
  113. #else    /* Xenix.  */
  114.     "$(COMPILE.s) -o$@ $<",
  115. #endif    /* Not Xenix.  */
  116.     ".S.o",
  117. #if !defined(M_XENIX) || defined(__GNUC__)
  118.     "$(COMPILE.S) -o $@ $<",
  119. #else    /* Xenix.  */
  120.     "$(COMPILE.S) -o$@ $<",
  121. #endif    /* Not Xenix.  */
  122.     ".c.o",
  123.     "$(COMPILE.c) $< $(OUTPUT_OPTION)",
  124.     ".cc.o",
  125.     "$(COMPILE.cc) $< $(OUTPUT_OPTION)",
  126.     ".C.o",
  127.     "$(COMPILE.C) $< $(OUTPUT_OPTION)",
  128.     ".f.o",
  129.     "$(COMPILE.f) $< $(OUTPUT_OPTION)",
  130.     ".p.o",
  131.     "$(COMPILE.p) $< $(OUTPUT_OPTION)",
  132.     ".F.o",
  133.     "$(COMPILE.F) $< $(OUTPUT_OPTION)",
  134.     ".r.o",
  135.     "$(COMPILE.r) $< $(OUTPUT_OPTION)",
  136.     ".mod.o",
  137.     "$(COMPILE.mod) -o $@ $<",
  138.  
  139.     ".c.ln",
  140.     "$(LINT.c) -C$* $<",
  141.     ".y.ln",
  142.     "$(YACC.y) $< \n $(LINT.c) -C$* y.tab.c \n $(RM) y.tab.c",
  143.     ".l.ln",
  144.     "@$(RM) $*.c\n $(LEX.l) $< > $*.c\n$(LINT.c) -i $*.c -o $@\n $(RM) $*.c",
  145.  
  146.     ".y.c",
  147. #ifdef __MSDOS__
  148.     "$(YACC.y) $< \n mv -f ytab.c $@",
  149. #else
  150.     "$(YACC.y) $< \n mv -f y.tab.c $@",
  151. #endif
  152.     ".l.c",
  153.     "@$(RM) $@ \n $(LEX.l) $< > $@",
  154.  
  155.     ".F.f",
  156.     "$(PREPROCESS.F) $< $(OUTPUT_OPTION)",
  157.     ".r.f",
  158.     "$(PREPROCESS.r) $< $(OUTPUT_OPTION)",
  159.  
  160.     /* This might actually make lex.yy.c if there's no %R%
  161.        directive in $*.l, but in that case why were you
  162.        trying to make $*.r anyway?  */
  163.     ".l.r",
  164.     "$(LEX.l) $< > $@ \n mv -f lex.yy.r $@",
  165.  
  166.     ".S.s",
  167.     "$(PREPROCESS.S) $< > $@",
  168.  
  169.     ".texinfo.info",
  170.     "$(MAKEINFO) $< -o $@",
  171.  
  172.     ".texi.info",
  173.     "$(MAKEINFO) $< -o $@",
  174.  
  175.     ".txinfo.info",
  176.     "$(MAKEINFO) $< -o $@",
  177.  
  178.     ".tex.dvi",
  179.     "$(TEX) $<",
  180.  
  181.     ".texinfo.dvi",
  182.     "$(TEXI2DVI) $<",
  183.  
  184.     ".texi.dvi",
  185.     "$(TEXI2DVI) $<",
  186.  
  187.     ".txinfo.dvi",
  188.     "$(TEXI2DVI) $<",
  189.  
  190.     ".w.c",
  191.     "$(CTANGLE) $< - $@",    /* The `-' says there is no `.ch' file.  */
  192.  
  193.     ".web.p",
  194.     "$(TANGLE) $<",
  195.  
  196.     ".w.tex",
  197.     "$(CWEAVE) $< - $@",    /* The `-' says there is no `.ch' file.  */
  198.  
  199.     ".web.tex",
  200.     "$(WEAVE) $<",
  201.  
  202.     0, 0,
  203.   };
  204.  
  205. static char *default_variables[] =
  206.   {
  207.     "AR", "ar",
  208.     "ARFLAGS", "rv",
  209.     "AS", "as",
  210. #ifdef GCC_IS_NATIVE
  211.     "CC", "gcc",
  212.     "CXX", "gcc",
  213. #else
  214.     "CC", "cc",
  215.     "CXX", "g++",
  216. #endif
  217.  
  218.     /* This expands to $(CO) $(COFLAGS) $< $@ if $@ does not exist,
  219.        and to the empty string if $@ does exist.  */
  220.     "CHECKOUT,v",
  221.     "$(patsubst $@-noexist,$(CO) $(COFLAGS) $< $@,\
  222.         $(filter-out $@,$(firstword $(wildcard $@) $@-noexist)))",
  223.  
  224.     "CO", "co",
  225.     "CPP", "$(CC) -E",
  226. #ifdef    CRAY
  227.     "CF77PPFLAGS", "-P",
  228.     "CF77PP", "/lib/cpp",
  229.     "CFT", "cft77",
  230.     "CF", "cf77",
  231.     "FC", "$(CF)",
  232. #else    /* Not CRAY.  */
  233. #ifdef    _IBMR2
  234.     "FC", "xlf",
  235. #else
  236. #ifdef    __convex__
  237.     "FC", "fc",
  238. #else
  239.     "FC", "f77",
  240. #endif /* __convex__ */
  241. #endif /* _IBMR2 */
  242.     /* System V uses these, so explicit rules using them should work.
  243.        However, there is no way to make implicit rules use them and FC.  */
  244.     "F77", "$(FC)",
  245.     "F77FLAGS", "$(FFLAGS)",
  246. #endif    /* Cray.  */
  247.     "GET", SCCS_GET,
  248.     "LD", "ld",
  249. #ifdef GCC_IS_NATIVE
  250.     "LEX", "flex",
  251. #else
  252.     "LEX", "lex",
  253. #endif
  254.     "LINT", "lint",
  255.     "M2C", "m2c",
  256. #ifdef    pyr
  257.     "PC", "pascal",
  258. #else
  259. #ifdef    CRAY
  260.     "PC", "PASCAL",
  261.     "SEGLDR", "segldr",
  262. #else
  263.     "PC", "pc",
  264. #endif    /* CRAY.  */
  265. #endif    /* pyr.  */
  266. #ifdef GCC_IS_NATIVE
  267.     "YACC", "bison -y",
  268. #else
  269.     "YACC", "yacc",
  270. #endif
  271.     "MAKEINFO", "makeinfo",
  272.     "TEX", "tex",
  273.     "TEXI2DVI", "texi2dvi",
  274.     "WEAVE", "weave",
  275.     "CWEAVE", "cweave",
  276.     "TANGLE", "tangle",
  277.     "CTANGLE", "ctangle",
  278.  
  279.     "RM", "rm -f",
  280.  
  281.     "LINK.o", "$(CC) $(LDFLAGS) $(TARGET_ARCH)",
  282.     "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  283.     "LINK.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  284.     "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  285.     "COMPILE.C", "$(COMPILE.cc)",
  286.     "LINK.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  287.     "LINK.C", "$(LINK.cc)",
  288.     "YACC.y", "$(YACC) $(YFLAGS)",
  289.     "LEX.l", "$(LEX) $(LFLAGS) -t",
  290.     "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c",
  291.     "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  292.     "COMPILE.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  293.     "LINK.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  294.     "COMPILE.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -c",
  295.     "LINK.r", "$(FC) $(FFLAGS) $(RFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  296.     "COMPILE.def", "$(M2C) $(M2FLAGS) $(DEFFLAGS) $(TARGET_ARCH)",
  297.     "COMPILE.mod", "$(M2C) $(M2FLAGS) $(MODFLAGS) $(TARGET_ARCH)",
  298.     "COMPILE.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  299.     "LINK.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  300.     "LINK.s", "$(CC) $(ASFLAGS) $(LDFLAGS) $(TARGET_MACH)",
  301.     "COMPILE.s", "$(AS) $(ASFLAGS) $(TARGET_MACH)",
  302.     "LINK.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)",
  303.     "COMPILE.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c",
  304. #if !defined(M_XENIX) || defined(__GNUC__)
  305.     "PREPROCESS.S", "$(CC) -E $(CPPFLAGS)",
  306. #else    /* Xenix.  */
  307.     "PREPROCESS.S", "$(CC) -EP $(CPPFLAGS)",
  308. #endif    /* Not Xenix.  */
  309.     "PREPROCESS.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -F",
  310.     "PREPROCESS.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -F",
  311.     "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
  312.  
  313. #ifndef    NO_MINUS_C_MINUS_O
  314. #if !defined(M_XENIX) || defined(__GNUC__)
  315.     "OUTPUT_OPTION", "-o $@",
  316. #else    /* Xenix.  */
  317.     "OUTPUT_OPTION", "-Fo$@",
  318. #endif    /* Not Xenix.  */
  319. #endif
  320.  
  321.     0, 0
  322.   };
  323.  
  324. /* Set up the default .SUFFIXES list.  */
  325.  
  326. void
  327. set_default_suffixes ()
  328. {
  329.   suffix_file = enter_file (".SUFFIXES");
  330.  
  331.   if (no_builtin_rules_flag)
  332.     (void) define_variable ("SUFFIXES", 8, "", o_default, 0);
  333.   else
  334.     {
  335.       char *p = default_suffixes;
  336.       suffix_file->deps = (struct dep *)
  337.     multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1),
  338.             sizeof (struct dep));
  339.       (void) define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0);
  340.     }
  341. }
  342.  
  343. /* Enter the default suffix rules as file rules.  This used to be done in
  344.    install_default_implicit_rules, but that loses because we want the
  345.    suffix rules installed before reading makefiles, and thee pattern rules
  346.    installed after.  */
  347.  
  348. void
  349. install_default_suffix_rules ()
  350. {
  351.   register char **s;
  352.   
  353.   if (no_builtin_rules_flag)
  354.     return;
  355.  
  356.  for (s = default_suffix_rules; *s != 0; s += 2)
  357.     {
  358.       register struct file *f = enter_file (s[0]);
  359.       /* Don't clobber cmds given in a makefile if there were any.  */
  360.       if (f->cmds == 0)
  361.     {
  362.       f->cmds = (struct commands *) xmalloc (sizeof (struct commands));
  363.       f->cmds->filename = 0;
  364.       f->cmds->commands = s[1];
  365.       f->cmds->command_lines = 0;
  366.     }
  367.     }
  368. }
  369.  
  370.  
  371. /* Install the default pattern rules.  */
  372.  
  373. void
  374. install_default_implicit_rules ()
  375. {
  376.   register struct pspec *p;
  377.   
  378.   if (no_builtin_rules_flag)
  379.     return;
  380.  
  381.   for (p = default_pattern_rules; p->target != 0; ++p)
  382.     install_pattern_rule (p, 0);
  383.  
  384.   for (p = default_terminal_rules; p->target != 0; ++p)
  385.     install_pattern_rule (p, 1);
  386. }
  387.  
  388. void
  389. define_default_variables ()
  390. {
  391.   register char **s;
  392.  
  393.   for (s = default_variables; *s != 0; s += 2)
  394.     (void) define_variable (s[0], strlen (s[0]), s[1], o_default, 1);
  395. }
  396.